package com.atwork.wuhua.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.atwork.wuhua.R;
import com.atwork.wuhua.bean.HomePageBean;
import com.atwork.wuhua.utils.GlideUtils.GlideUtil;
import com.atwork.wuhua.utils.Util;
import com.atwork.wuhua.wrideg.StarBar;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class SubLaunchAdapter extends BaseQuickAdapter<HomePageBean.DataBean, BaseViewHolder> {
    private Context context;

    public SubLaunchAdapter(Context context, int layoutResId, @Nullable List<HomePageBean.DataBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, HomePageBean.DataBean item) {
        String distance = Util.getDistance(context, Double.parseDouble(item.getLongitude()), Double.parseDouble(item.getLatitude()));


        helper.addOnClickListener(R.id.img_thumb);

        if (item.getAlbum() != null && item.getAlbum().size() > 0) {
            GlideUtil.loadImage(context, item.getAlbum().get(0), (ImageView) helper.getView(R.id.img_thumb));
        }
        helper.setText(R.id.tv_name, item.getName()).setText(R.id.tv_time, "营业时间：" + item.getOpen_time())
                .setText(R.id.tv_tel, "联系电话：" + item.getTel())
                .setText(R.id.tv_distance, distance);

        ((StarBar) helper.getView(R.id.starBar)).setIsOnTouch(false);
        ((StarBar) helper.getView(R.id.starBar)).setStarMark(Float.parseFloat(item.getStarts()));
    }
}
